package capricornus.components
{
	import capricornus.core.StageManager;
	import capricornus.events.StageEvent;
	
	import flash.display.Sprite;
	import flash.display.Stage;
	
	public class ComponentsManager
	{
		private static var _singleton:Boolean = true;
		private static var _ins:ComponentsManager;
		
		private var _oldStageW:int;
		private var _oldStageH:int;
		private var _container:Sprite;
		
		private var _backLayer:Sprite;
		/**
		 * 窗口都放这里 
		 */		
		private var _middleLayer:Sprite;
		private var _foreLayer:Sprite;
		private var _alertLayer:Sprite;
		private var _modelAlertLayer:Sprite;
		private var _tipLayer:Sprite;
		private var _mouseLayer:Sprite;
		
		public function ComponentsManager()
		{
			if( _singleton ) throw new Error("不能实例化ComponentsManager单例!");
			_singleton = true;
		}
		
		public static function get instance():ComponentsManager
		{
			if( _ins==null )
			{
				_singleton = false;
				_ins = new ComponentsManager();
				_ins.initialize();
			}
			return _ins;
		}
		
		private function initialize():void
		{
			var stage:Stage = StageManager.instance.stage;
			_oldStageW = stage.stageWidth;
			_oldStageH = stage.stageHeight;
			
			_container = new Sprite();
			stage.addChild( _container );
			_container.mouseEnabled = false;
			
			_backLayer = new Sprite();
			_backLayer.mouseEnabled = false;
			_container.addChild( _backLayer );
			
			_middleLayer = new Sprite();
			_middleLayer.mouseEnabled = false;
			_container.addChild( _middleLayer );
			
			_foreLayer = new Sprite();
			_foreLayer.mouseEnabled = false;
			_container.addChild( _foreLayer );
			
			_alertLayer = new Sprite();
			_alertLayer.mouseEnabled = false;
			_container.addChild( _alertLayer );
			
			_modelAlertLayer = new Sprite();
			_modelAlertLayer.mouseEnabled = false;
			_container.addChild( _modelAlertLayer );
			
			_tipLayer = new Sprite();
			_tipLayer.mouseEnabled = false;
			_tipLayer.mouseChildren = false;
			_container.addChild( _tipLayer );
			
			_mouseLayer = new Sprite();
			_mouseLayer.mouseChildren = false;
			_mouseLayer.mouseEnabled = false;
			_container.addChild( _mouseLayer );
		}
		
		public function get backLayer():Sprite
		{
			return _backLayer;
		}
		
		public function get middleLayer():Sprite
		{
			return _middleLayer;
		}
		
		public function get foreLayer():Sprite
		{
			return _foreLayer;
		}
		
		public function get alertLayer():Sprite
		{
			return _alertLayer;
		}
		
		public function get modelAlertLayer():Sprite
		{
			return _modelAlertLayer;
		}
		
		public function get tipLayer():Sprite
		{
			return _tipLayer;
		}
		
		public function get mouseLayer():Sprite
		{
			return _mouseLayer;
		}
	}
}